/***
	templates: default
	name: utility.js
	designer: kukei
	Copyright(C) 2011 SupDo.com
	Create Date: 2011-10-05
	Modify Date: 2011-04-27
***/
//子菜单标志；
isSubNavHide=true;

function tojson(str){return eval('({'+str.replace(new RegExp("=","g"),':"').replace(new RegExp("&","g"),'",')+'"})');}
function bindForms(){
	$(".fromField[cValid=true] > input").focusout(
		function(){var postView=$(this).parent().attr('view');if(!postView)postView=$(this).parentsUntil('form').parent('form').attr('view');
		  $.post("/valid"+postView+".do", {_field:this.name, _value:this.value},
		  function(data){postdata = tojson(this.data);
		  	if(data.flag){$('#'+postdata._field+'_info').html(data.html);}else{$.dialog.alert(data.msg, function(){});}}
		,'json');
	});
}
function del(pre,action,id){
	var url="/"+pre+"/delete!"+action+"-"+id+".do";
	if(pre=='')url="/delete!"+action+"-"+id+".do";
	deleteByID(url, 'e-'+id);
}
function deleteByID(url, id){
	$("#"+id).attr('bgcolor','#FFCC99');
	$.dialog.confirm('确定要删除此项么?',
		function(){
			$.post(url, {_retType:"json"},function (data){
						if(data.flag){$("#"+id).attr('bgcolor','#CC0000').fadeOut("slow",function(){$(this).remove();});}
						else $.dialog.alert(data.msg, function(){$("#"+id).removeAttr('bgcolor');});
			},'json');
		},
		function(){$("#"+id).removeAttr('bgcolor');}
	);
}
function submit(){
	alert('test');
}

//管理列表事件
function listHover(){
	$(".elementList tbody tr").hover(
			  function(){$(this).addClass("trhover");},
			  function(){$(this).removeClass("trhover");}
	);
	$(".elementList :input").attr('disabled',true);
}

//子菜单显示与隐藏
function navHaver(){
	addSubNav();
	$('.moreNav,.subNav,.subNavRight').hover(
		function(){
			if($(this).attr('class')=="moreNav"){
				$('.subNav,.subNavRight').hide();
				$(this).next('.subNav,.subNavRight').fadeIn(400);
			}
			isSubNavHide=false;
		},
		function(){
			setTimeout(function(){
				if(isSubNavHide){$('.subNav,.subNavRight').fadeOut(400);}
			},600);
			isSubNavHide=true;
		}
	);
}
//添加子菜单
function addSubNav(){
	$("ul.preNav > li[cnt]").each(function(i){
		eli = $(this);
		alist = $("#hidenNav > a[parent='"+eli.attr("id")+"']");
		if(alist.length>0){
			eli.children("a").addClass("moreNav");
			ehtml = '<div class="subNav"><div class="r_t"><span class="r_tl"></span><span class="r_tr"></span></div><div class="r_c">'
				+ $("<p></p>").append(alist).html() + '</div><div class="r_b"><span class="r_bl"></span><span class="r_br"></span></div></div>';
			eli.append(ehtml);
		}
	})
}